package com.groupbuying.customer.controller;

import com.groupbuying.customer.service.CustomerMainService;
import com.groupbuying.customer.utils.ParamUtils;
import com.groupbuying.customer.utils.apiresult.ApiResult;
import com.groupbuying.customer.utils.RedisUtils;
import com.groupbuying.customer.utils.ReturnUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("用户登录接口")
@RestController
@RequestMapping()
public class CustomerController {
    @Autowired
    private CustomerMainService customerMainService;


    /**
     * @api {post} /register  注册用户接口
     * @apiExample author mayunfei
     * tar 用于:客户端小程序 调用
     * date 2019/10/31
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} mobile:手机号
     * @apiParam {Map} password:密码
     * @apiParam {Map} captcha:验证码
     * @apiSuccess {ApiResult} success:登录成功; failure:请求
     * @apiSuccess {ApiResult}  failure:请求
     * @apiSuccess {ApiResult}  access_token失败
     */
    @ApiOperation(value = "注册用户接口", notes = "创建用户信息的相关一系列操作")
    @PostMapping("/register")
    public ApiResult register(@RequestParam Map<String, Object> params) {
        return customerMainService.customerRegister(params);
    }


    /**
     * @api {post} /wxregister 微信原生异步
     * @apiExample author mayunfei
     * tar 用于:客户端小程序 调用
     * date 2019/10/31
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} wxCode:微信codee
     * @apiSuccess {ApiResult} success:登录成功; failure:请求
     * @apiSuccess {ApiResult}  failure:请求
     * @apiSuccess {ApiResult}  access_token失败
     */
    @ApiOperation(value = "微信用户注册", notes = "优惠买单，微信用户注册")
    @PostMapping("/wxregister")
    public ApiResult wxregister(@RequestParam Map<String, Object> params) {
        return customerMainService.customerWXRegister(params);
    }

    /**
     * @api {post} /getLogin 账户登录接口
     * @apiExample author mayunfei
     * tar 用于:客户端小程序  调用
     * date 2019/10/31
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} mobile:手机号
     * @apiParam {Map} password:密码
     * @apiParam {Map} wxCode:微信code
     * @apiSuccess {ApiResult} success:登录成功; failure:请求
     * @apiSuccess {ApiResult}  failure:请求
     * @apiSuccess {ApiResult}  access_token失败
     */
    @ApiOperation(value = "账户登录接口", notes = "用于用户账户登录")
    @PostMapping("/getLogin")
    public ApiResult getLogin(@RequestParam Map<String, Object> params) {
        return customerMainService.customerLogin(params);
    }

    /**
     * @api {post} /redPacketRegister 红包登录
     * @apiExample author mayunfei
     * tar 用于:微信小程序  调用
     * date 2019/11/29
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} mobile:手机号
     * @apiParam {Map} password:密码
     * @apiParam {Map} wxCode:微信code
     * @apiSuccess {ApiResult} success:登录成功; failure:请求
     * @apiSuccess {ApiResult}  failure:请求
     * @apiSuccess {ApiResult}  access_token失败
     */
    @PostMapping("/redPacketRegister")
    public ApiResult redPacketRegister(@RequestParam Map<String, Object> params) {
        return customerMainService.redPacketRegister(params);
    }

    /**
     * //用户通过静默授权code获取unionId 登录
     *
     * @Author Vincentxin
     * @Date 2019/12/23 21:31
     * @param code
     * @return com.groupbuying.customer.utils.apiresult.ApiResult
     **/
    @GetMapping("/unionIdLogin")
    public ApiResult unionIdLogin(String code){
        return null;
    }

    /**
     * //用户通过授权userInfo 解析unionId登录
     *
     * @Author Vincentxin
     * @Date 2019/12/23 21:31
     * @param params
     * @return com.groupbuying.customer.utils.apiresult.ApiResult
     **/
    @PostMapping("/authorizationUserInfoLogin")
    public ApiResult authorizationUserInfoLogin(@RequestParam Map<String,String> params){
        return null;
    }
}
